package util

import (
	"crypto/md5"
	"fmt"
	"strconv"
)

func ReturnData(code int, message string, data ...interface{}) interface{} {
	if len(data) > 0 {
		return map[string]interface{}{"code": code, "message": message, "data": data[0]}
	} else {
		return map[string]interface{}{"code": code, "message": message, "data": ""}
	}
}

func Md5(str string) string {
	return fmt.Sprintf("%x", md5.Sum([]byte(str)))
}

func Str2Int(str string) int {
	num, err := strconv.Atoi(str)
	if err != nil {
		return 0
	}
	return num
}

func Int2Str(num int) string {
	return strconv.Itoa(num)
}
